package com.itfreer.special.index;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.alibaba.dubbo.config.annotation.Service;
import com.itfreer.form.api.BaseDao;
import com.itfreer.form.api.BaseServiceImp;

/**
 * 定义指标实现类
 */
@Component
@Service(interfaceClass = IndexDataService.class, path = "indexdata")
public class IndexDataServiceImp extends BaseServiceImp<IndexDataEntity> implements IndexDataService {

	@Autowired
	private IndexDataDao dao;

	@Override
	protected BaseDao<IndexDataEntity> getDao() {
		return dao;
	}

	/**
	 * 是否为租户实体对象
	 */
	@Override
	protected boolean isTenant() {
		return false;
	}

	public List<Map<String, Object>> getIndexDataBy(Map<String, Object> map) {
		String indexid, indexname = null, adminid = null;
		Integer year = null;
		if (map.get("indexid") != null && !"".equals(map.get("indexid"))) {
			indexid = (String) map.get("indexid");
		} else {
			return null;
		}
		if (map.get("adminid") != null && !"".equals(map.get("adminid"))) {
			adminid = (String) map.get("adminid");
		}

		if (map.get("year") != null && !"".equals(map.get("year"))) {
			year = Integer.valueOf((String) map.get("year"));
		}

		if (map.get("indexname") != null && !"".equals(map.get("indexname"))) {
			indexname = (String) map.get("indexname");
		}

		List<Map<String, Object>> list = dao.getIndexDataBy(indexid, adminid, year, indexname);
		/*
		 * list.forEach(m -> { Map<?, ?> map2 =
		 * dao.getadminById(String.valueOf(m.get("adminid"))); m.put("adminname",
		 * map2.get("adminname")); });
		 */
		return list;
	}

	public List<Map<String, Object>> selectIndexName(Map<String, Object> map) {
		String indexname = null;
		if (map.get("indexid") != null && ((String) map.get("indexid")).length() > 0) {
			indexname = (String) map.get("indexid");
		} else {
			return null;
		}
		return dao.getIndexName(indexname);
	}
}
